//
//  BHNavigationController.m
//  InsuranceMarketing
//
//  Created by initial on 2018/1/24.
//  Copyright © 2018年 initial. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()<UINavigationBarDelegate,UIGestureRecognizerDelegate>

@end

@implementation BaseNavigationController


-(void)viewDidLoad{
    [super viewDidLoad];
    

}


-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    // 左上角的返回键
    // 注意：第一个控制器不需要返回键
    // if不是第一个push进来的子控制器{
    if (self.childViewControllers.count >= 1) {
        // 左上角的返回按钮
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(0, 0, 30, 60);
        [backButton setImage:[UIImage imageNamed:@"leftArrow"] forState:UIControlStateNormal];
        [backButton setImage:[UIImage imageNamed:@"leftArrow"] forState:UIControlStateHighlighted];
        // 让按钮内部的所有内容左对齐
        backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //        [backButton sizeToFit];
        [backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0); // 这里微调返回键的位置可以让它看上去和左边紧贴
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        viewController.hidesBottomBarWhenPushed = YES; // 隐藏底部的工具条
    }

    [super pushViewController:viewController animated:YES];
}

- (void)back:(UIViewController *)vc
{
    [self popViewControllerAnimated:YES];// 这里不用写self.navigationController，因为它自己就是导航控制器
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
